package com.sky.mapper;

import com.sky.autofill.AutoFill;
import com.sky.entity.Category;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ClassifyMapper {
    List<Category> getAllCateGory(String name, Integer type);

    @AutoFill(OperationType.INSERT)
    void addCategory(Category category);

    @Select("select count(*) from category where name = #{name}")
    Integer selectByName(String name);

    @Select("select count(*) from category where sort =#{sort}")
    Integer selectBySort(Integer sort);

    @Delete("delete from category where id = #{id}")
    void deleteCategory(String id);

    @Select("select * from category where id = #{id}")
    Category selectById(String id);

    @AutoFill(OperationType.UPDATE)
    void update(Category category);

    @Select("select count(*) from category where id != #{id} and name = #{name};")
    Integer selectByNameNotSelf(String name, long id);

    @Select("select * from category where type = #{type};")
    List<Category> getCateGory(Integer type);

    @Select("select count(*) from dish where category_id = #{id}")
    int getDish(String id);

    @Select("select count(*) from setmeal where category_id = #{id}")
    int getSetmeal(String id);
}
